package com.wu.client.controller;

import com.wu.client.service.MainCommentsService;
import com.wu.client.service.ReplyCommentsService;
import com.wu.client.vo.req.comment.CommentReplyReq;
import com.wu.client.vo.req.comment.MainCommentReq;
import com.wu.client.vo.res.PageResp;
import com.wu.client.vo.res.comment.MainCommentAddResp;
import com.wu.client.vo.res.comment.MainCommentResp;
import com.wu.client.vo.res.comment.ReplyCommentAddResp;
import com.wu.client.vo.res.comment.ReplyCommentResp;
import com.wu.common.convertion.result.Result;
import com.wu.common.convertion.result.Results;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author Cousin
 * @date 2025/3/8
 * @Description
 */
//http://localhost:8888/api/comments?contentId=1&contentType=album&page=1&limit=20
@RestController
@RequestMapping("/comments")
@RequiredArgsConstructor
public class CommentsController {
    private final MainCommentsService mainCommentsService;
    private final ReplyCommentsService replyCommentsService;
    @GetMapping()
    public Result<PageResp<MainCommentResp>> getMainComments(@RequestParam String contentId, @RequestParam  String contentType,
                                                             @RequestParam(required = false) Long userId
            , @RequestParam  Integer page, @RequestParam  Integer limit){
       return Results.success(mainCommentsService.getMainCommentsInPage(contentId,contentType,userId,page,limit));

    }
    @GetMapping("/{parentId}/replies")
    public Result<PageResp<ReplyCommentResp>> getReplies(@PathVariable String parentId,@RequestParam(required = false) Long userId,
                                                         @RequestParam(defaultValue = "1")  Integer page, @RequestParam(defaultValue = "10")  Integer limit){
        return Results.success(replyCommentsService.getReplyInPage(userId,parentId,page,limit));
    }
    @PostMapping
    public Result<MainCommentAddResp> addComment(@RequestBody MainCommentReq mainCommentReq){
        return Results.success(mainCommentsService.addComment(mainCommentReq));
    }
    //http://localhost:8888/api/comments/1/reply
    @PostMapping("/{parentId}/reply")
    public Result<ReplyCommentAddResp> addReply(@RequestBody CommentReplyReq commentReplyReq, @PathVariable String parentId){
        return Results.success(replyCommentsService.addReply(commentReplyReq,parentId));
    }
    @DeleteMapping("/{mainCommentId}")
    public Result<Void> deleteMainComment(@PathVariable String mainCommentId){
        mainCommentsService.deleteMainComment(mainCommentId);
        return Results.success();
    }
    @DeleteMapping("/replies/{replyId}")
    public Result<Void> deleteReply(@PathVariable String replyId){
        replyCommentsService.deleteReply(replyId);
        return Results.success();
    }


}
